#region Copyright Jonathan Quiros

//	
// All rights are reserved. Reproduction or transmission in whole or in 
// part, in any form or by any means, electronic, mechanical or otherwise, 
// is prohibited without the prior written consent of the copyright owner.
//
// Filename: PermissionsHelper.cs
//

#endregion

using System.Web;
using System.Web.Mvc;
using Novagoal.Utils;
using Ids.Web.Security;

namespace Novagoal.Website.WebApp.Helpers
{
    public static class PermissionsHelper
    {
        #region CONSTANTS



        #endregion

        #region PROPERTIES

        

        #endregion

        #region PUBLIC METHODS

        public static bool UserIsAtLeast(this HtmlHelper htmlHelper, Enums.Roles role)
        {
            var result = false;
            if(HttpContext.Current.User.Identity.IsAuthenticated)
            {
                var user = htmlHelper.ViewContext.Controller.ControllerContext.HttpContext.GetSecurityContext().User;
                var currentRole = user != null ? user.Role : string.Empty;

                switch (role)
                {
                    case Enums.Roles.BasicUser:
                        result |= currentRole == Enums.GetEnumValue(Enums.Roles.BasicUser);
                        result |= currentRole == Enums.GetEnumValue(Enums.Roles.AdvancedUser);
                        result |= currentRole == Enums.GetEnumValue(Enums.Roles.SuperUser);
                        break;
                    case Enums.Roles.AdvancedUser:
                        result |= currentRole == Enums.GetEnumValue(Enums.Roles.AdvancedUser);
                        result |= currentRole == Enums.GetEnumValue(Enums.Roles.SuperUser);
                        break;
                    case Enums.Roles.SuperUser:
                        result |= currentRole == Enums.GetEnumValue(Enums.Roles.SuperUser);
                        break;
                }
            }

            return result;
        }

        #endregion

        #region PRIVATE METHODS



        #endregion
    }
}